package com.taiyi.renaissancemall.ui.mine.team;

import android.content.Intent;

import com.taiyi.renaissancemall.Utils.ToastUtils;
import com.taiyi.renaissancemall.Utils.Utils;
import com.taiyi.renaissancemall.base.BasePresent;
import com.taiyi.renaissancemall.base.MyApp;
import com.taiyi.renaissancemall.bean.BaseResultBean;
import com.taiyi.renaissancemall.bean.CollectBean;
import com.taiyi.renaissancemall.bean.MyTeamCountBean;
import com.taiyi.renaissancemall.bean.MyTeamListBean;
import com.taiyi.renaissancemall.net.BaseUrl;
import com.taiyi.renaissancemall.net.HttpUtils;
import com.taiyi.renaissancemall.net.callbck.JsonCallback;
import com.taiyi.renaissancemall.ui.login.LoginActivity;
import com.taiyi.renaissancemall.ui.mine.collect.MyCollectView;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Response;

public class MyTeamPresent extends BasePresent<MyTeamView> {

    public void getMyTeamCount(String date) {
        Map<String, String> map = new HashMap<>();
        map.put("createtime", date);
        HttpUtils.postRequest(BaseUrl.MY_TEAM_COUNT, this, map, new JsonCallback<BaseResultBean<MyTeamCountBean>>() {
            @Override
            public BaseResultBean<MyTeamCountBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<MyTeamCountBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.MyTeamSuccess(response.body().data);
                } else if (response.body().code == -1) {
                    ToastUtils.showShortToast(response.body().msg_cn);
                    Utils.getSpUtils().remove("token");
                    Intent intent = new Intent(MyApp.getInstance(), LoginActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    MyApp.getInstance().startActivity(intent);
                } else {
                    view.MyTeamFailure(response.body().msg_cn);
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<MyTeamCountBean>> response) {
                super.onError(response);
            }
        });
    }

    public void getMyTeamList(String xtype, String pagenum) {
        Map<String, String> map = new HashMap<>();
        map.put("xtype", xtype);
        map.put("pagenum", pagenum);
        HttpUtils.postRequest(BaseUrl.MY_TEAM_LIST, this, map, new JsonCallback<BaseResultBean<MyTeamListBean>>() {
            @Override
            public BaseResultBean<MyTeamListBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<MyTeamListBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.MyTeamListSuccess(response.body().data);
                } else {
                    view.MyTeamListFailure(response.body().msg_cn);
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<MyTeamListBean>> response) {
                super.onError(response);
            }
        });
    }

}
